const userModel = require('./model/userModel');
const askModel = require('./model/askModel');

// 添加用户
module.exports.addUserDao = async function (userInfo) {
    const result = await userModel.create(userInfo);
    return result.dataValues;
}
// 分页获取用户
module.exports.getUserListDao = async function (page, limit) {
    return await userModel.findAndCountAll({
        offset: (page * 1 - 1) * limit,
        limit: limit * 1,
        order: [
            ['graduationYear', 'desc']
        ]
    });
}
// 根据id 获取单个用户信息
module.exports.getUserByIdDao = async function (id) {
    return await userModel.findByPk(id);
}
// 根据id 查找某个用户提出的所有问题和回复的所有问题
module.exports.getUserConsultById = async function (id) {
    return await userModel.findOne({
        where: { id: 1 },
        include: [
            { model: askModel, as: 'askQuestions' },
            { model: askModel, as: 'replyQuestions' },
        ],
    });
};